Protect bitset tests under libcpp-no-exceptions Bitset tests feature a sequence of tests of increasing bitset sizes, but these tests rely on exceptions when the bitset size is less than 50 elements. This change adds a flag to tell whether a test should throw. If it must throw it will be skipped under no-exceptions. Differential Revision: https://reviews.llvm.org/D26140 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@286474 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp b/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp index 88ce8e9..18a64a2 100644 --- a/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/flip_one.pass.cpp
@@ -7,13 +7,14 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions // test bitset<N>& flip(size_t pos); #include <bitset> #include <cstdlib> #include <cassert> +#include "test_macros.h" + template <std::size_t N> std::bitset<N> make_bitset() @@ -25,11 +26,15 @@ } template <std::size_t N> -void test_flip_one() +void test_flip_one(bool test_throws) { std::bitset<N> v = make_bitset<N>(); +#ifdef TEST_HAS_NO_EXCEPTIONS + if (test_throws) return; +#else try { +#endif v.flip(50); bool b = v[50]; if (50 >= v.size()) @@ -39,21 +44,25 @@ assert(v[50] != b); v.flip(50); assert(v[50] == b); + assert(!test_throws); +#ifndef TEST_HAS_NO_EXCEPTIONS } catch (std::out_of_range&) { + assert(test_throws); } +#endif } int main() { - test_flip_one<0>(); - test_flip_one<1>(); - test_flip_one<31>(); - test_flip_one<32>(); - test_flip_one<33>(); - test_flip_one<63>(); - test_flip_one<64>(); - test_flip_one<65>(); - test_flip_one<1000>(); + test_flip_one<0>(true); + test_flip_one<1>(true); + test_flip_one<31>(true); + test_flip_one<32>(true); + test_flip_one<33>(true); + test_flip_one<63>(false); + test_flip_one<64>(false); + test_flip_one<65>(false); + test_flip_one<1000>(false); } diff --git a/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp b/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp index f01d35b..6847694 100644 --- a/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
@@ -7,18 +7,23 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions // test bitset<N>& reset(size_t pos); #include <bitset> #include <cassert> +#include "test_macros.h" + template <std::size_t N> -void test_reset_one() +void test_reset_one(bool test_throws) { std::bitset<N> v; +#ifdef TEST_HAS_NO_EXCEPTIONS + if (test_throws) return; +#else try { +#endif v.set(); v.reset(50); if (50 >= v.size()) @@ -28,21 +33,25 @@ assert(!v[i]); else assert(v[i]); + assert(!test_throws); +#ifndef TEST_HAS_NO_EXCEPTIONS } catch (std::out_of_range&) { + assert(test_throws); } +#endif } int main() { - test_reset_one<0>(); - test_reset_one<1>(); - test_reset_one<31>(); - test_reset_one<32>(); - test_reset_one<33>(); - test_reset_one<63>(); - test_reset_one<64>(); - test_reset_one<65>(); - test_reset_one<1000>(); + test_reset_one<0>(true); + test_reset_one<1>(true); + test_reset_one<31>(true); + test_reset_one<32>(true); + test_reset_one<33>(true); + test_reset_one<63>(false); + test_reset_one<64>(false); + test_reset_one<65>(false); + test_reset_one<1000>(false); } diff --git a/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp b/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp index debe543..1c8d6a1 100644 --- a/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp
@@ -7,47 +7,60 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions // test bitset<N>& set(size_t pos, bool val = true); #include <bitset> #include <cassert> +#include "test_macros.h" + template <std::size_t N> -void test_set_one() +void test_set_one(bool test_throws) { std::bitset<N> v; +#ifdef TEST_HAS_NO_EXCEPTIONS + if (test_throws) return; +#else try +#endif { v.set(50); if (50 >= v.size()) assert(false); assert(v[50]); + assert(!test_throws); } +#ifndef TEST_HAS_NO_EXCEPTIONS catch (std::out_of_range&) { + assert(test_throws); } try +#endif { v.set(50, false); if (50 >= v.size()) assert(false); assert(!v[50]); + assert(!test_throws); } +#ifndef TEST_HAS_NO_EXCEPTIONS catch (std::out_of_range&) { + assert(test_throws); } +#endif } int main() { - test_set_one<0>(); - test_set_one<1>(); - test_set_one<31>(); - test_set_one<32>(); - test_set_one<33>(); - test_set_one<63>(); - test_set_one<64>(); - test_set_one<65>(); - test_set_one<1000>(); + test_set_one<0>(true); + test_set_one<1>(true); + test_set_one<31>(true); + test_set_one<32>(true); + test_set_one<33>(true); + test_set_one<63>(false); + test_set_one<64>(false); + test_set_one<65>(false); + test_set_one<1000>(false); } diff --git a/test/std/utilities/template.bitset/bitset.members/test.pass.cpp b/test/std/utilities/template.bitset/bitset.members/test.pass.cpp index 161afd1..1a2d706 100644 --- a/test/std/utilities/template.bitset/bitset.members/test.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/test.pass.cpp
@@ -7,13 +7,14 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions // test constexpr bool test(size_t pos) const; #include <bitset> #include <cstdlib> #include <cassert> +#include "test_macros.h" + template <std::size_t N> std::bitset<N> make_bitset() @@ -25,30 +26,38 @@ } template <std::size_t N> -void test_test() +void test_test(bool test_throws) { const std::bitset<N> v1 = make_bitset<N>(); +#ifdef TEST_HAS_NO_EXCEPTIONS + if (test_throws) return; +#else try { +#endif bool b = v1.test(50); if (50 >= v1.size()) assert(false); assert(b == v1[50]); + assert(!test_throws); +#ifndef TEST_HAS_NO_EXCEPTIONS } catch (std::out_of_range&) { + assert(test_throws); } +#endif } int main() { - test_test<0>(); - test_test<1>(); - test_test<31>(); - test_test<32>(); - test_test<33>(); - test_test<63>(); - test_test<64>(); - test_test<65>(); - test_test<1000>(); + test_test<0>(true); + test_test<1>(true); + test_test<31>(true); + test_test<32>(true); + test_test<33>(true); + test_test<63>(false); + test_test<64>(false); + test_test<65>(false); + test_test<1000>(false); }